package com.hotel.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hotel.entity.Dish;
import com.hotel.entity.Log;
import com.hotel.mapper.DishMapper;
import com.hotel.mapper.LogMapper;
import com.hotel.service.DishService;
import com.hotel.service.LogService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @program: springboot-vue
 * @description: LogService实现类
 * @author: Mr.Nie
 * @create: 2022-05-12 15:47
 **/
@Service
public class LogServiceImpl implements LogService {


    @Resource
    private LogMapper logMapper;

    @Override
    public IPage<Log> getOperationLog(String username, String createTime, String endTime, Integer current, Integer size) {
        List<Log> log = logMapper.getOperationLog(username, createTime, endTime);
        List pageList = new ArrayList<>();
        int curIdx = current > 1 ? (current - 1) * size : 0;
        for (int i = 0; i < size && curIdx + i < log.size(); i++) {
            pageList.add(log.get(curIdx + i));
        }
        IPage page = new Page<>(current, size);
        page.setRecords(pageList);
        page.setTotal(log.size());
        return page;
    }

    @Override
    public Log getLog(String id) {
        return logMapper.getLog(id);
    }

    @Override
    public int deleteLog(String id) {
        int i = logMapper.deleteLog(id);
        return i;
    }

    @Override
    public int clearLog() {
        return logMapper.clearLog();
    }

    /**
     * 保存登入日志
     * @param log
     */
    @Override
    public void saveLog(Log log) {
        logMapper.insert(log);
    }

}
